import { deepCopy, formatNumber, messages, setLocalStorageWithAutoStringify } from 'share/common';
import ReportCommonUtils from 'components/template/graphic-report/report-common-utils';
import React from 'react';
import { Tooltip } from 'antd';
import {
  getBarOptionsColors,
  getIndexActive
} from 'containers/data-center/report/graphic-report/echarts-data-transfer/utils';

export const COLOR_LIST = [
  '#1F70FC',
  '#49BFFF',
  '#4EDAA5',
  '#FC9A28',
  '#FD647A'
];

export const LINEAR_COLOR_LIST = [
  {
    start: 'rgba(31,112,252,0.30)',
    end: 'rgba(75,141,255,0.00)'
  },
  {
    start: 'rgba(136,225,255,0.30)',
    end: 'rgba(80,192,255,0.00)'
  },
  {
    start: 'rgba(136,255,200,0.30)',
    end: 'rgba(80,255,124,0.00)'
  },
  {
    start: 'rgba(255,184,102,0.30)',
    end: 'rgba(255,184,102,0.00)'
  },
  {
    start: 'rgba(255,110,171,0.30)',
    end: 'rgba(255,110,171,0.00)'
  },
];

const BAR_COLOR_LIST = [
  '#5BA4FF',
  '#FF956D',
  '#49C7BA',
  '#4A8DFF'
];

const BAR_COLOR_LIST_TEST = [
  {
    type: 'linear',
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0, color: 'rgba(91,164,255,1)' // 0% 处的颜色
    }, {
      offset: 1, color: 'rgba(91,164,255,0.7)' // 100% 处的颜色
    }],
    global: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0, color: 'rgba(255,149,109,1)' // 0% 处的颜色
    }, {
      offset: 1, color: 'rgba(255,149,109,0.7)' // 100% 处的颜色
    }],
    global: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0, color: 'rgba(73,199,186,1)' // 0% 处的颜色
    }, {
      offset: 1, color: 'rgba(73,199,186,0.7)' // 100% 处的颜色
    }],
    global: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 0,
    y: 0,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0, color: 'rgba(74,141,255,1)' // 0% 处的颜色
    }, {
      offset: 1, color: 'rgba(74,141,255,0.7)' // 100% 处的颜色
    }],
    global: false // 缺省为 false
  }
];

const BAR_COLOR_LIST_TEST_VERTICAL = [
  {
    type: 'linear',
    x: 1,
    y: 1,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0, color: 'rgba(91,164,255,1)' // 0% 处的颜色
    }, {
      offset: 1, color: 'rgba(91,164,255,0.7)' // 100% 处的颜色
    }],
    global: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 1,
    y: 1,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0, color: 'rgba(255,149,109,1)' // 0% 处的颜色
    }, {
      offset: 1, color: 'rgba(255,149,109,0.7)' // 100% 处的颜色
    }],
    global: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 1,
    y: 1,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0, color: 'rgba(73,199,186,1)' // 0% 处的颜色
    }, {
      offset: 1, color: 'rgba(73,199,186,0.7)' // 100% 处的颜色
    }],
    global: false // 缺省为 false
  },
  {
    type: 'linear',
    x: 1,
    y: 1,
    x2: 0,
    y2: 1,
    colorStops: [{
      offset: 0, color: 'rgba(74,141,255,1)' // 0% 处的颜色
    }, {
      offset: 1, color: 'rgba(74,141,255,0.7)' // 100% 处的颜色
    }],
    global: false // 缺省为 false
  }
];

const LINE_COLOR_LIST = [
  '#4B8DFF',
  '#50C0FF',
  '#FC9A28',
  '#4EDAA5'
];

const PIE_COLOR_LIST = [
  '#2774F8',
  '#63ADFF',
  '#5EC6FF',
  '#8CD6FF',
  '#FC9A28',
  '#FFB866',
  '#FD647A',
  '#B68CFF'
];

const pageIcon = {
  pageIcons: {
    vertical: [
      'M904.533333 584.5333330000001c-17.066667 17.066667-42.666667 17.066667-59.733333 0L512 251.73333300000002 179.2 584.5333330000001c-17.066667 17.066667-42.666667 17.066667-59.733333 0-17.066667-17.066667-17.066667-42.666667 0-59.733333l362.666666-362.666667c8.533333-8.533333 19.2-12.8 29.866667-12.8s21.333333 4.266667 29.866667 12.8l362.666666 362.666667c17.066667 17.066667 17.066667 42.666667 0 59.733333z',
      'M904.533333 221.866667l-362.666666 362.666666c-17.066667 17.066667-42.666667 17.066667-59.733334 0l-362.666666-362.666666c-17.066667-17.066667-17.066667-42.666667 0-59.733334 17.066667-17.066667 42.666667-17.066667 59.733333 0L512 494.933333l332.8-332.8c8.533333-8.533333 19.2-12.8 29.866667-12.8s21.333333 4.266667 29.866666 12.8c17.066667 17.066667 17.066667 42.666667 0 59.733334z'
    ],
    horizontal: [
      'M384 384L731.733333 693.333333c17.066667 14.933333 19.2 42.666667 4.266667 59.733334-14.933333 17.066667-42.666667 19.2-59.733333 4.266666l-384-341.333333c-10.666667-8.533333-14.933333-19.2-14.933334-32s4.266667-23.466667 14.933334-32l384-341.333333c8.533333-6.4 19.2-10.666667 27.733333-10.666667 12.8 0 23.466667 4.266667 32 14.933333 14.933333 17.066667 14.933333 44.8-4.266667 59.733334L384 384z',
      'M731.733333 416l-384 341.333333c-17.066667 14.933333-44.8 14.933333-59.733333-4.266666-14.933333-17.066667-14.933333-44.8 4.266667-59.733334L640 384 292.266667 74.666667c-17.066667-14.933333-19.2-42.666667-4.266667-59.733334 8.533333-8.533333 19.2-14.933333 32-14.933333 10.666667 0 19.2 4.266667 27.733333 10.666667l384 341.333333c8.533333 8.533333 14.933333 19.2 14.933334 32s-4.266667 23.466667-14.933334 32z'
    ]
  },
  pageIconSize: 12,
  pageIconColor: '#1F70FC',
  pageTextStyle: {
    fontSize: 12
  }
}

export function toggleShowLabel({ config, options }) {
  const { showLabel } = config;
  if (options && options.series) {
    options.series.forEach(item => {
      if (item.label) {
        item.label.normal.show = showLabel;
      }
    });
  }
  return Object.assign({}, options);
}

export function popoverTitle(columns) {
  columns.forEach(column => {
    column.title = <Tooltip placement="top" title={column.title}>{column.title}</Tooltip>;
    return column;
  });
  return columns;
}

export function commonUtilsFactory(options) {

  const {
    context,
    config,
    reportType,
    reportKeyPrefix,
    allowSetting = true,
    allowExport = false,
  } = options;

  let props = {
    allowSetting,
    allowExport
  };

  if (allowSetting) {
    let { showLabel } = config;
    const settingChildren = [{
      id: 'showLabel',
      label: messages('basic-10.key162')/*展示数值*/,
      value: showLabel
    }];

    const onSettingChange = (id, value) => {
      if (id === 'showLabel') {
        const { reportConfig } = context.state;
        reportConfig[reportType].showLabel = value;
        setLocalStorageWithAutoStringify(reportKeyPrefix + reportType, value);
        context.setState({
          reportConfig
        });
      }
    };
    props.settingChildren = settingChildren;
    props.onSettingChange = onSettingChange;
  }

  if (allowExport) {
    const propsArray = ['reportCode', 'exportDisable', 'exportParams', 'exportType', 'exportUrl'];

    propsArray.forEach(key => {
      props[key] = options[key];
    });
  }

  return (
    <ReportCommonUtils
      {...props}
    />
  );
}

/**
 * 通用饼图模板生成方法
 * @params verticalLegend legend是否垂直排列
 * @returns {{tooltip: {trigger: string, formatter: (function(*): string)}, legend: {bottom: number, left: string, data: Array}, series: {type: string, radius: string[], data: Array}[]}}
 */
export function pieTemplateFactory(verticalLegend) {

  let legend = verticalLegend ? {
    type: 'scroll',
    ...pageIcon,
    orient: 'vertical',
    top: 'center',
    right: 10,
    itemGap: 20,
    data: []
  } : {
    type: 'scroll',
    ...pageIcon,
    bottom: 10,
    left: 'center',
    data: []
  };
  return {
    grid: { containLabel: true },
    tooltip: {
      textStyle: {
        fontSize: 10
      },
      trigger: 'item',
      formatter: (item) => lengthStrShow(item.name) + ':</br>' + lengthStrShow(item.data.label) + ':' + formatNumber(item.value) + '</br>' + item.data._percentageStr
    },
    legend,
    series: [
      {
        type: 'pie',
        radius: '55%',
        center: ['40%', '50%'],
        data: [],
        label: {
          normal: {
            show: true,
            formatter: '{b} {c} ({d}%)',
            position: 'right'
          }
        },
        labelLine: {
          show: true
        }
      }
    ],
    color: PIE_COLOR_LIST
  };
}

/**
 * 通用柱状图模板生成方法
 * @params colorIndex 使用第几种颜色
 */

const barTemplate = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    },
    textStyle: {
      fontSize: 10
    },
    formatter: (params = []) => {
      return `${params[0].data.valueBelongName}<br>${params.map(item => `${item.data.label}：${item.data.value}`)
        .join('<br>')}`;
    }
  },
  axisLabel: {
    interval: 119, // 自定义显示X轴坐标显示间隔
    textStyle: {
      fontSize: '10',
    },
  },
  grid: {
    y: 20,
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  yAxis: [
    {
      data: [],
      inverse: true,
      axisLine: {
        lineStyle: {
          color: '#DBE6F3'
        }
      },
      axisTick: {
        show: false
      },
      // axisLabel: {
      //   interval: 0,
      //   rotate: 45,
      //   margin: 10,
      //   fontSize: 12,
      //   formatter: (value) => {   //关键代码
      //     let res = value
      //     if (res.length > 7) {
      //       res = res.substring(0, 6) + '..'
      //     }
      //     return res
      //   }
      // },
    }
  ],
  xAxis: [
    {
      type: 'value',
      boundaryGap: ['0', '15%'],  // 右侧留白用于显示label
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: '#EBF0F5'
        }
      },
      axisLine: {
        lineStyle: {
          color: '#DBE6F3'
        }
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        interval: 0,
        rotate: 45,
        margin: 10,
        color: '#B5C0CE',
        fontSize: 12
      },
    }
  ],
  series: [
    {
      type: 'bar',
      // barWidth: 10,
      barMaxWidth: 25,
      barMinWidth: 2,
      data: [],
      itemStyle: {},
      label: {
        normal: {
          show: true,
          position: 'right',
          fontSize: '10',
          formatter: (params) => `${params.value}`
        }
      },
    }
  ],
  color: BAR_COLOR_LIST_TEST
};

export function barTemplateFactory(isHorizon, needDataZoom) {
  let YDataZoom = [{
    type: 'slider',
    show: true,
    yAxisIndex: [0],
    start: 0,
    end: 50
  }];
  let XDataZoom = [{
    type: 'slider',
    show: true,
    xAxisIndex: [0],
    start: 0,
    end: 50
  }];
  if (isHorizon) {
    //数据缩放先不上

    let result = deepCopy(barTemplate);
    result.color = BAR_COLOR_LIST_TEST_VERTICAL;
    if (needDataZoom) {
      result.dataZoom = YDataZoom;
      result.grid.right = 45;
    }
    return result;
  } else {
    let result = deepCopy(barTemplate);
    if (needDataZoom) {
      result.dataZoom = XDataZoom;
      result.grid.bottom = 45;
    }
    return result;
  }
}

const lineTemplate = {
  tooltip: {
    trigger: 'axis',
    textStyle: {
      fontSize: 10
    },
  },
  grid: {
    left: '5%',
    right: '5%',
    bottom: '5%',
    top: '10%',
    containLabel: true
  },
  xAxis: {
    data: [],
    axisLine: {
      lineStyle: {
        color: '#DBE6F3'
      }
    },
    axisTick: {
      show: false
    },
    axisLabel: {
      color: '#6C788C',
      fontSize: 12
    },
  },
  yAxis: {
    type: 'value',
    boundaryGap: ['0', '10%'],  // 顶部留白
    splitLine: {
      lineStyle: {
        type: 'dashed',
        color: '#EBF0F5'
      }
    },
    axisLine: {
      show: false
    },
    axisTick: {
      show: false
    },
    axisLabel: {
      show: false
    },
  },
  series: [
    {
      type: 'line',
      label: {
        show: true,
        position: 'top',
        formatter: (params) => `${params.value.toFixed(2)}`
      },
      data: []
    },
  ],
  color: COLOR_LIST
};

export function lineTemplateFactory(needDataZoom, verticalLegend) {
  let legend = verticalLegend ? {
    type: 'scroll',
    ...pageIcon,
    orient: 'vertical',
    top: 'center',
    right: 10,
    itemGap: 20,
    data: []
  } : {
    type: 'scroll',
    ...pageIcon,
    bottom: 5,
    left: 'center',
    data: []
  };
  let XDataZoom = [{
    type: 'slider',
    show: true,
    xAxisIndex: [0],
    start: 0,
    end: 50
  }];
  let result = deepCopy(lineTemplate);
  if (needDataZoom) {
    result.dataZoom = XDataZoom;
    result.grid.bottom = 45;
  }
  result.legend = legend;
  return result;
}

const areaTemplate = {
  tooltip: {
    trigger: 'axis',
    textStyle: {
      fontSize: 10
    },
  },
  grid: {
    left: '5%',
    right: '5%',
    bottom: '5%',
    top: '10%',
    containLabel: true
  },
  xAxis: {
    data: [],
    axisLine: {
      lineStyle: {
        color: '#DBE6F3'
      }
    },
    axisTick: {
      show: false
    },
    axisLabel: {
      color: '#6C788C',
      fontSize: 12
    },
  },
  yAxis: {
    type: 'value',
    boundaryGap: ['0', '10%'],  // 顶部留白
    splitLine: {
      lineStyle: {
        type: 'dashed',
        color: '#EBF0F5'
      }
    },
    axisLine: {
      show: false
    },
    axisTick: {
      show: false
    },
    axisLabel: {
      show: false
    },
  },
  series: [
    {
      areaStyle: {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0, color: 'rgba(136,255,200,0.30)' // 0% 处的颜色
            },
            {
              offset: 1, color: 'rgba(80,255,124,0.00)' // 100% 处的颜色
            }
          ],
          colorList: LINEAR_COLOR_LIST,
          global: false,
        }
      },
      stack: 'add',
      smooth: true,
      type: 'line',
      label: {
        show: true,
        position: 'top',
        formatter: (params) => `${params.value.toFixed(2)}`
      },
      data: []
    },
  ],
  color: COLOR_LIST
};

export function areaTemplateFactory(needDataZoom, verticalLegend) {
  let legend = verticalLegend ? {
    type: 'scroll',
    ...pageIcon,
    orient: 'vertical',
    top: 'center',
    right: 10,
    itemGap: 20,
    data: []
  } : {
    type: 'scroll',
    ...pageIcon,
    bottom: 5,
    left: 'center',
    data: []
  };
  let XDataZoom = [{
    type: 'slider',
    show: true,
    xAxisIndex: [0],
    start: 0,
    end: 50
  }];
  let result = deepCopy(areaTemplate);
  if (needDataZoom) {
    result.dataZoom = XDataZoom;
    result.grid.bottom = 45;
  }
  result.legend = legend;
  return result;
}

const radarTemplate = {
  tooltip: {
    textStyle: {
      fontSize: 10
    }
  },
  // toolbox: {
  //   show: true,
  //   feature: {
  //     saveAsImage: {
  //       type: 'png',
  //       show: true
  //     }
  //   }
  // },
  grid: { containLabel: true },
  radar: {
    name: {
      textStyle: {
        color: '#fff',
        backgroundColor: '#6C788C',
        borderRadius: 3,
        padding: [3, 5]
      }
    },
    center: ['40%', '50%'],
    radius: '55%'
  },
  series: [
    {
      type: 'radar',
      label: {
        show: true,
        formatter: (params) => `${params.value.toFixed(2)}`
      },
      data: [],
      areaStyle: {
        color: {
          type: 'radial',
          x: 0.5,
          y: 0.5,
          r: 0.5,
          colorStops: [
            {
              offset: 1, color: 'rgba(136,255,200,0.30)' // 100% 处的颜色
            },
            {
              offset: 0, color: 'rgba(80,255,124,0.00)' // 0% 处的颜色
            }
          ],
          colorList: LINEAR_COLOR_LIST,
          global: false,
        }
      }
    },
  ],
  color: COLOR_LIST
};

export function radarTemplateFactory(verticalLegend) {
  let result = deepCopy(radarTemplate);
  let legend = verticalLegend ? {
    type: 'scroll',
    ...pageIcon,
    orient: 'vertical',
    top: 'center',
    right: 10,
    itemGap: 20,
    data: []
  } : {
    type: 'scroll',
    ...pageIcon,
    bottom: 10,
    left: 'center',
    data: []
  };
  result.legend = legend;
  return result;
}


/**
 * 点击时设置饼状图柱子的颜色
 * @param params  被点击过的数据
 * @param options 当前画布被渲染的参数
 * @param compareKey 比较属性
 * @returns {*|Array}
 */
export function getCustomBarOptionsColorsByName(params, options, compareKey) {
  let itemLength = options.series[0].data.length;
  let indexActive = getIndexActive(params, options, compareKey);
  let copyData = deepCopy(options.series);
  let vertical = options.xAxis[0].type === 'value';
  options.series.forEach((series, index) => {
    series.data.forEach((data, dataIndex) => {
      if (dataIndex === indexActive) {
        copyData[index].data[dataIndex].itemStyle = {};
        copyData[index].data[dataIndex].itemStyle.color = vertical ? BAR_COLOR_LIST_TEST_VERTICAL[index % 5] : BAR_COLOR_LIST_TEST[index % 5];
        copyData[index].data[dataIndex].isActive = 'Y';
      } else {
        copyData[index].data[dataIndex].isActive = 'N';
        copyData[index].data[dataIndex].itemStyle = {};
        copyData[index].data[dataIndex].itemStyle.color = '#ddd';
      }
    });
  });
  // options.series[0].data.forEach((item, index)=>{
  //   if (index === indexActive) {
  //     copyData[index].itemStyle = {}
  //     copyData[index].itemStyle.color = BAR_COLOR_LIST_TEST_VERTICAL
  //   } else {
  //     copyData[index].itemStyle = {}
  //     copyData[index].itemStyle.color = '#ddd'
  //   }
  // })
  return copyData;
  // return getCustomBarOptionsColors(indexActive, itemLength)
}

export function getCustomCommonOptionsColorsByNameRemove(options) {
  let copyData = deepCopy(options.series);
  options.series && options.series.forEach((series, index) => {
    series.data.forEach((data, dataIndex) => {
      delete copyData[index].data[dataIndex].itemStyle;
      delete copyData[index].data[dataIndex].isActive;
    });
  });
  return copyData;
}

/**
 * 点击时设置饼状图柱子的颜色
 * @param params  被点击过的数据
 * @param options 当前画布被渲染的参数
 * @param compareKey 比较属性
 * @returns {*|Array}
 */
export function getCustomPieOptionsColorsByName(params, options, compareKey) {
  let itemLength = options.series[0].data.length;
  let indexActive = getIndexActive(params, options, compareKey);
  let copyData = deepCopy(options.series);
  options.series.forEach((series, index) => {
    series.data.forEach((data, dataIndex) => {
      if (dataIndex === indexActive) {
        copyData[index].data[dataIndex].itemStyle = {};
        copyData[index].data[dataIndex].itemStyle.color = PIE_COLOR_LIST[dataIndex % 8];
        copyData[index].data[dataIndex].isActive = 'Y';
      } else {
        copyData[index].data[dataIndex].isActive = 'N';
        copyData[index].data[dataIndex].itemStyle = {};
        copyData[index].data[dataIndex].itemStyle.color = '#ddd';
      }
    });
  });
  return copyData;
}

/**
 * 点击时设置折线图/面积图 图 折线 的颜色
 * @param params  被点击过的数据
 * @param options 当前画布被渲染的参数
 * @param compareKey 比较属性
 * @returns {*|Array}
 */
export function getCustomLineOptionsColorsByName(params, options, compareKey, isArea) {
  let indexActive = getIndexActive(params, options, compareKey);
  let copyData = deepCopy(options.series);
  options.color = '#ddd';
  options.series.forEach((series, index) => {
    if (isArea) {
      copyData[index].areaStyle.color = {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
          offset: 0, color: 'rgba(221,221,221, 0.3)' // 0% 处的颜色
        }, {
          offset: 1, color: 'rgba(221,221,221,0)' // 100% 处的颜色
        }],
        global: false // 缺省为 false
      };
    }
    series.data.forEach((data, dataIndex) => {
      if (dataIndex === indexActive) {
        copyData[index].data[dataIndex].itemStyle = {};
        copyData[index].data[dataIndex].itemStyle.color = COLOR_LIST[index % 5];
        copyData[index].data[dataIndex].itemStyle.borderColor = COLOR_LIST[index % 5];
        copyData[index].data[dataIndex].itemStyle.borderWidth = 2;
        copyData[index].data[dataIndex].isActive = 'Y';
      } else {
        copyData[index].data[dataIndex].isActive = 'N';
        copyData[index].data[dataIndex].itemStyle = {};
        copyData[index].data[dataIndex].itemStyle.color = '#ddd';
        copyData[index].data[dataIndex].itemStyle.borderColor = '#ddd';
        copyData[index].data[dataIndex].itemStyle.borderWidth = 2;
      }
    });
  });
  return copyData;
}

export function getCustomLineOptionsColorsByNameRemove(options, isArea) {
  let copyData = deepCopy(options.series);
  options.color = COLOR_LIST;
  options.series.forEach((series, index) => {
    if (isArea) {
      copyData[index].areaStyle = {};
      copyData[index].areaStyle.color = {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
          offset: 0, color: LINEAR_COLOR_LIST[index % 5].start // 0% 处的颜色
        }, {
          offset: 1, color: LINEAR_COLOR_LIST[index % 5].end // 100% 处的颜色
        }],
        global: false // 缺省为 false
      };
    }
    series.data.forEach((data, dataIndex) => {
      delete copyData[index].data[dataIndex].itemStyle;
      delete copyData[index].data[dataIndex].isActive;
    });
  });
  return copyData;
}

// 以下是周立的工具函数
/*
* 多字符换行
* 传入一个500个字符以下的字符串，转换为多行，因为在图表里面显示不全
* 每行40个
* */
export function lengthStrShow(str) {
  if (!str) return str;
  let regExp = /^(?!.*?[\u3000-\u303F\u4DC0-\u4DFF\u2800-\u28FF\u3200-\u32FF\u3300-\u33FF\u2700-\u27BF\u2600-\u26FF\uFE10-\uFE1F\uFE30-\uFE4F])[\u4e00-\u9fbb\u2E80-\uFE4F]+$/i;
  let resLine = [];
  if (str && str.length >= 40) {
    let singleLine = [];
    for (let i = 0, len = str.length; i < len; i++) {
      if (regExp.test(str[i])) {
        singleLine.push(str[i]);
        singleLine.push('');
      } else {
        singleLine.push(str[i]);
      }
      if (singleLine.length >= 40) {
        let cache = [...singleLine];
        resLine.push(cache.join(''));
        resLine.push('</br>');
        singleLine = [];
      }
    }
    resLine.push(singleLine.join(''));
    return resLine.join('');
  } else {
    return str;
  }
}

/*
* 截取字符
* 字符串太长，截取前6个，其他以点显示
* */
export function _ts(str) {
  if (!str) return str;
  let regExp = /^(?!.*?[\u3000-\u303F\u4DC0-\u4DFF\u2800-\u28FF\u3200-\u32FF\u3300-\u33FF\u2700-\u27BF\u2600-\u26FF\uFE10-\uFE1F\uFE30-\uFE4F])[\u4e00-\u9fbb\u2E80-\uFE4F]+$/i;
  let res = '';
  let len = str.length;
  let sum = 0;
  for (let i = 0; i < len; i++) {
    let char = str[i];
    if (regExp.test(char)) {
      res += char;
      sum += 2;
    } else {
      res += char;
      sum += 1;
    }
    if (sum >= 10 && i < len) {
      res += '...';
      break;
    }
  }
  return res;
}
